<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="form" :model="form" label-width="80px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="房间名称">
                <el-input
                  class="w-200"
                  v-model.trim="form.name"
                  placeholder="请输入房间名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="房间楼层">
                <el-select
                  v-model="form.type"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="房间分类">
                <el-select
                  v-model="form.source"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="房间床位">
                <el-select
                  v-model="form.source"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="房间状态">
                <el-select
                  v-model="form.source"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">房间列表</div>
        <div class="op_right">
          <button class="primary_button" @click="AddRoom">添加房间</button>
        </div>
      </div>

      <div class="table_list">
        <el-table :data="ClientList" stripe style="width: 100%">
          <el-table-column prop="date" label="房间排序" width="300">
          </el-table-column>
          <el-table-column prop="totalBalance" label="房间" width="300">
          </el-table-column>
          <el-table-column prop="customerType" label="房间楼层">
          </el-table-column>
          <el-table-column prop="sourceName" label="商品分类">
          </el-table-column>
          <el-table-column prop="days" label="房间床位">
            <!-- <template>
                 {{ scope.row.days }}
              </template> -->
          </el-table-column>
          <el-table-column prop="createTime" label="商品状态">
          </el-table-column>
          <el-table-column prop="date" label="操作">
            <el-button size="mini" type="text" @click="Edit">编辑</el-button>
            <el-button size="mini" type="text" @click="Takedown">
              <span class="separate_left">|</span> 下架<span
                class="separate_right"
                >|</span
              ></el-button
            >
            <el-button size="mini" type="text" @click="DelSort">删除</el-button>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <!-- 新增房间 -->
      <el-dialog
        :title="title"
        :visible.sync="newClientdialogVisible"
        width="400px"
        :before-close="CancelClientSubmit"
        class="no-dialog-padding"
      >
        <span>
          <div class="add_room">
            <el-form
              ref="newClientForm"
              :rules="newClientRules"
              :model="newClientForm"
            >
              <el-row :gutter="40">
                <el-col :span="24">
                  <el-form-item label="房间名称" prop="name">
                    <el-input
                      class="w-100"
                      v-model="newClientForm.name"
                      placeholder="请输入房间名称"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="房间楼层" prop="password">
                    <el-input
                      class="w-100"
                      v-model="newClientForm.password"
                      placeholder="请选择房间楼层"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="房间分类" prop="sex">
                    <el-select
                      v-model="newClientForm.sex"
                      placeholder="请选择"
                      class="w-100"
                    >
                      <el-option
                        v-for="item in Sexoptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="房间床位" prop="referrer">
                    <el-select
                      v-model="newClientForm.referrer"
                      placeholder="请选择房间床位"
                      class="w-100"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button class="cancel_btn" @click="CancelClientSubmit"
            >取 消</el-button
          >
          <el-button type="primary" @click="ClientSubmit">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
  
  <script>
import {
  getClientList,
  CreateClient,
} from "@/api/business/client";
import { phoneTest } from "@/utils/regular";
export default {
  name: "EryuoaStoreFrontendClientlist",

  data() {
    return {
      newClientdialogVisible: false, // 新增房间
      loading: false,
      activeIndex: 1,
      form: {
        name: "",
        type: "",
        source: "",
      },
      title: "",
      ClientList: [], // 客户列表数据

      options: [],
      ClientSourceData: [], // 客户来源数据
      MemberCardList: [
        {
          id: 1212,
        },
      ], // 会员卡列表

      // 客户类型
      customerTypeObj: {
        1: "散客",
        2: "会员",
      },

      typeObj: {
        1: "充值",
        2: "消费",
        3: "钱包",
        4: "调整",
      },

      newClientRules: {
        name: [{ required: true, message: "请输入房间名称", trigger: "blur" }],
        password: [
          { required: true, message: "请选择房间楼层", trigger: "blur" },
        ],

        sex: [{ required: true, message: "请选择房间分类", trigger: "blur" }],
        referrer: [
          { required: true, message: "请选择房间床位", trigger: "blur" },
        ],
      },

      newClientForm: {
        name: "",
        mobile: "",
        mobile2: "",
        password: "",
        sex: "",
        birthday: "",
        referrer: "",
        sourceId: "",
      },

      value: "",
      // 查询参数
      queryParams: {
        customerType: "", // 客户类型 1普通账户，即散客 2会员卡账户，即会员.
        // mobile: "", // 手机号
        sourceId: "", // 客户来源
        pageNo: 1,
        pageSize: 10,
      },

      // 性别
      Sexoptions: [
        {
          value: 0,
          label: "未知",
        },
        {
          value: 1,
          label: "男",
        },
        {
          value: 2,
          label: "女",
        },
      ],
      total: 0,
    };
  },

  created() {
    this.getList();
  },

  mounted() {},

  methods: {

    // 编辑房间
    Edit() {
      this.newClientdialogVisible = true;
      this.title = "编辑房间";
    },

    // 添加房间
    AddRoom() {
      this.newClientdialogVisible = true;
      this.title = "添加房间";
      // getClientSourceList().then((res) => {
      //   const { code, data } = res;
      //   if (code === 0) {
      //     this.ClientSourceData = data;
      //   }
      // });
    },

    getList() {
      this.loading = true;
      getClientList(this.queryParams)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.ClientList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 列表 下架
    Takedown() {
      this.$confirm("商品下架后门店无法使用, 是否下架?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 商品列表 删除
    DelSort() {
      this.DeleteSort();
    },

    DeleteSort() {
      this.$confirm("分类删除后无法撤销, 是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.form.name = undefined;
      this.form.mobile = "";
      this.getList();
    },

    // 新增房间 弹框 确认
    ClientSubmit() {
      this.$refs["newClientForm"].validate((valid) => {
        if (valid) {
          this.NewClient();
        } else {
        }
      });
    },

    NewClient() {
      CreateClient(this.newClientForm).then((res) => {
        const { code } = res;
        if (code === 0) {
          this.getList();
          this.CancelClientSubmit();
        }
      });
    },

    // 取消 弹框 关闭
    CancelClientSubmit() {
      this.newClientdialogVisible = false;
      this.resetForm("newClientForm");
    },

    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
  margin-left: 15px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}

.add_room {
  margin: 0 40px;
}
</style>